<template>
	<view class="container">
		<view class="top-box" id="topBox">
			<view class="box">
				<view class="text-black">选择全部</view>
				<u-checkbox-group @change="selectAllOperate" shape="circle">
					<u-checkbox :checked="selectAll" size="48rpx" iconSize="36rpx"></u-checkbox>
				</u-checkbox-group>
			</view>
		</view>
		<scroll-view v-if="storeList.length>0" :style="{ height: height + 'px'}" scroll-y="true"
			:scroll-with-animation="true" :enable-back-to-top="true" @scrolltolower="reachBottom">
			<view class="container-box">
				<view v-for="(item,index) in storeList" :key="index" class="text-black">
					<view class="title u-flex u-row-between">
						<view class="box-left" @click.stop="showOperate(index)">
							<u-icon v-if="!item.show" name="play-right-fill" size="12"></u-icon>
							<u-icon v-else name="arrow-down-fill" size="12"></u-icon>
							<text class="box-left-name">{{item.storeName}}</text>
						</view>
						<view class="right-checkbox">
							<u-checkbox-group @change.stop="checkStore($event,index)" shape="circle">
								<u-checkbox :checked="item.select" size="48rpx" iconSize="36rpx"
									:name="item.id"></u-checkbox>
							</u-checkbox-group>
						</view>
					</view>
					<u-transition :show="item.show" mode="fade">
						<view class="parameter-container">
							<view class="box">
								<view>售价</view>
								<u--input border="none" maxlength="7" type="digit"
									@input="checkRetailPrice($event,index)" :value="item.retailPrice" fontSize="28rpx"
									inputAlign="right" placeholder="请输入售价" />
								<text class="u-p-l-20">元</text>
							</view>

							<view v-if="commodityType == 3">
								<view class="box" @click="ticketPackageTypeModelShow(item)">
									<view>套票类型</view>
									<view class="flex reset-box">
										<u--input v-model="item.ticketPackageTypeName" input-align="right" disabled
											disabledColor="#ffffff" placeholder="请选择" border="none"></u--input>
										<view class="u-p-l-10">
											<u-icon slot="right" name="arrow-right"></u-icon>
										</view>
									</view>
								</view>
								<view
									style="display: flex;align-items: center;justify-content: flex-end;padding: 0 30rpx 36rpx;"
									v-if="item.ticketPackageType != -1 && item.ticketPackageType != $ticketPackageTypeEnum.UNDATED">
									<view style="width: 100rpx;background: rgba(0, 0, 0, 0.05);">
										<u--input @change="calculateExpirationDays(item)" v-model="item.amount"
											inputAlign="center" :customStyle="numberOfPackageType" border="none"
											type="number" maxlength="6"></u--input>
									</view>
									<view class="u-m-l-15">{{item.packageTypeName}}</view>
								</view>

								<view class="box">
									<view style="flex: none;">总游玩次数</view>

									<view class="total-pay-box">
										<radio-group class="total-pay-radio-group"
											@change="itemChangeBooleanOfPlay(item,$event)">
											<radio :checked="item.booleanOfPlay == '0'" class="total-pay-radio-top"
												value="0" color="#6072FF">
												不限次
											</radio>
											<radio :checked="item.booleanOfPlay != '0'" class="total-pay-radio-bottom"
												value="1" color="#6072FF">
												<view class="total-pay-radio-bottom-view">
													<u--input @change="totalNumberOfPlayChange(item,$event)"
														v-model="item.totalNumberOfPlay" @input="integerTest($event,1)"
														inputAlign="center" placeholder="请输入次数" border="none"
														type="number" maxlength="6"></u--input>
													<view class="u-m-l-15">次</view>
												</view>
											</radio>
										</radio-group>
									</view>
								</view>

								<template v-if="checkPlayList.length > 0">
									<view style="color: #FF0101;font-size: 28rpx;margin-bottom: 20rpx;">
										设置了次数的，表示套票内该项目最多可玩数
									</view>
									<view class="u-p-b-20">
										<view v-for="(data,ind) in item.checkPlayList" :key="ind">
											<view style="display: flex;align-items: center;
											padding: 0 90rpx;
											">
												<view style="margin-bottom: 10rpx;width: 250rpx;">
													{{ind+1}}.{{data.name}}
												</view>
												<view style="color: #0583FE;" @click="showLimitTimesBoolean(item,data)">
													<view v-if="data.numberOfPlay == -1">
														设置次数
													</view>
													<view v-else>
														最多{{data.numberOfPlay}}次
													</view>
												</view>
											</view>
										</view>
									</view>
								</template>
								<view class="reset-container">
									<view class="flex">
										<view>首次使用时是否重设过期时间</view>
										<u-switch @change="switchReset(index)"
											:value="item.resetExpirationDate"></u-switch>
									</view>
									<view class="flex reset-box" v-if="item.resetExpirationDate">
										<view class="text-ash">过期天数重设到</view>
										<u--input border="none" type="number" @input="integerTest($event,2,index)"
											fontSize="28rpx" :value="item.numberOfDays" inputAlign="right"
											placeholder="请输入过期天数" maxlength="6">
										</u--input>
										<text class="u-p-l-20">天</text>
									</view>
								</view>
								<view class="box">
									<view>限制每天核销次数</view>
									<u-switch @change="switchOff(index)" :value="item.quantityWrittenOff"></u-switch>
								</view>
								<view class="box" v-if="item.quantityWrittenOff">
									<view>限制次数</view>
									<u--input type="number" :value="item.everydayQuantityWrittenOff" border="none"
										fontSize="28rpx" inputAlign="right" placeholder="请输入限制次数"
										@input="integerTest($event,3,index)" maxlength="6"></u--input>
									<text class="u-p-l-20">次</text>
								</view>
							</view>

							<!-- 套票和通用商品共用 start -->
							<view class="box">
								<view>兑换价格</view>
								<u-switch @change="switchPrice(index)" :value="item.openExchange"></u-switch>
							</view>
							<template v-if="item.openExchange">
								<view class="box">
									<view class="u-p-l-20">积分兑换</view>
									<u--input type="number" border="none" :value="item.integralConversionPrice"
										fontSize="28rpx" inputAlign="right" placeholder="请输入积分兑换价格"
										@input="integerTest($event,4,index)" maxlength="6"></u--input>
									<view class="u-m-l-15">积分</view>
								</view>
								<view class="box">
									<view class="u-p-l-20">彩票兑换</view>
									<u--input type="number" border="none" :value="item.lotteryConversionPrice"
										fontSize="28rpx" inputAlign="right" placeholder="请输入彩票兑换价格"
										@input="integerTest($event,5,index)" maxlength="6"></u--input>
									<view class="u-m-l-15">彩票</view>
								</view>
								<view class="box">
									<view class="u-p-l-20">游戏币兑换</view>
									<u--input type="number" border="none" :value="item.coinConversionPrice"
										fontSize="28rpx" inputAlign="right" placeholder="请输入游戏币兑换价格"
										@input="integerTest($event,6,index)" maxlength="6"></u--input>
									<view class="u-m-l-15">币</view>
								</view>
							</template>
							<view style="padding: 30rpx" class="box">
								<u-form-item label="上架终端" label-width="80" required>
									<view style="display: flex;">
										<view class="u-m-r-30">
											<u-checkbox-group>
												<u-checkbox :checked="item.posTerminal" @change="pos(index)"
													v-model="item.posTerminal" inactiveColor="#6072FF"
													label=" "></u-checkbox>
												<view class="u-m-l-20">收银系统</view>
											</u-checkbox-group>
										</view>
										<view>
											<u-checkbox-group>
												<u-checkbox :checked="item.integralMallTerminal" @change="goods(index)"
													v-model="item.integralMallTerminal" inactiveColor="#6072FF"
													label=" ">
												</u-checkbox>
												<view class="u-m-l-20">小程序商城</view>
											</u-checkbox-group>
										</view>
									</view>
								</u-form-item>
							</view>
							<template>
								<view class="box">
									<view>积分商城自助兑换</view>
									<u-switch @change="goodsExchange(index)"
										:value="item.integralMallSelfService"></u-switch>
								</view>
							</template>
							<!-- 套票和通用商品共用 end -->

							<!-- 通用商品才显示 start -->
							<template v-if="commodityType == 2">
								<view class="box">
									<view>开启回收</view>
									<u-switch @change="switchRecovery(index)" :value="item.openRecovery"></u-switch>
								</view>
							</template>
							<template v-if="item.openRecovery">
								<view class="box">
									<view class="u-p-l-20">积分回收</view>
									<u--input type="number" border="none" :value="item.recoveryPrice" inputAlign="right"
										fontSize="28rpx" placeholder="请输入积分回收价格" @input="integerTest($event,7,index)"
										maxlength="6">
									</u--input>
									<text class="u-p-l-20 font-8-28">积分</text>
								</view>
							</template>
							<view v-if="commodityType == 2" style="padding:30rpx" class="box">
								<u-form-item label="邮寄自提" label-width="80" required borderBottom>
									<view style="display: flex;">
										<view class="u-m-r-50">
											<u-checkbox-group>
												<u-checkbox :checked="item.isSelfMention"
													@change="isSelfMentionChange(index)" v-model="item.isSelfMention"
													inactiveColor="#6072FF" label=" "></u-checkbox>
												<view class="u-m-l-20">到店自提</view>
											</u-checkbox-group>
										</view>
										<view>
											<u-checkbox-group>
												<u-checkbox @change="isDirectMailChange(index)"
													:checked="item.isDirectMail" v-model="item.isDirectMail"
													inactiveColor="#6072FF" label=" ">
												</u-checkbox>
												<view class="u-m-l-20">快递包邮</view>
											</u-checkbox-group>
										</view>
									</view>
								</u-form-item>
							</view>
							<!-- 通用商品才显示 end -->
						</view>
					</u-transition>
				</view>
			</view>
			<view class="placeholder"></view>
		</scroll-view>

		<view class="footer" id="footer">
			<u-button type="primary" shape="circle" @click="keep()">保存</u-button>
		</view>
		<!-- 套票类型 -->
		<u-picker :show="ticketPackageTypeShow" :columns="ticketPackageTypeList" keyName="label" confirmColor="#6072FF"
			@confirm="ticketPackageTypeConfirm($event,form)" @cancel="ticketPackageTypeShow=false"
			@close="ticketPackageTypeShow=false" :closeOnClickOverlay="true" :defaultIndex="[0]">
		</u-picker>

		<u-modal :show="limitTimesBoolean" showCancelButton @cancel="limitTimesBoolean=false"
			@confirm="limitTimesConfirm()">
			<view style="display: flex;flex-direction: column;align-items: center;">
				<view style="display: flex;align-items: center;flex-wrap:wrap;text-align: center;"
					v-if="limitTimesCommodityStoreUpDown.totalTimes != -1">
					总次数为{{limitTimesCommodityStoreUpDown.totalTimes}}次，该项目最多可玩次数为
				</view>
				<view style="display: flex;align-items: center;flex-wrap:wrap;text-align: center;" v-else>
					总次数为无限次，该项目最多可玩次数为
				</view>
				<view style="margin-top:50rpx;">
					<u-number-box v-if="limitTimesCommodityStoreUpDown.totalTimes == -1" inputWidth="80" min="0"
						v-model="limitTimes"></u-number-box>
					<u-number-box v-else inputWidth="80" v-model="limitTimes" min="0"
						:max="limitTimesCommodityStoreUpDown.totalTimes"></u-number-box>
				</view>
				<view style="margin-top: 20rpx;color: #a8a8a8;font-size: 22rpx;">
					0为不限制次数
				</view>
			</view>
		</u-modal>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				limitTimesBoolean: false,
				limitTimesCommodityStoreUpDown: {},
				limitTimes: 0,
				indexTime: -1,
				limitTimesItem: {},
				minDate: '',
				numberOfPlayStyle: {
					width: '100rpx',
					background: 'rgba(0, 0, 0, 0.05)',
					height: '30rpx'
				},
				showTime: false,
				commodityType: 0,
				//选中的列表
				selectedStores: [],
				headerHeight: 0,
				footerHeight: 0,
				showIndex: -1,
				height: 0,
				show: false,
				selectAll: false,
				//场地列表
				storeList: [],
				//需要反显的列表
				reverseDisplayStoreList: [],
				reverseDisplayStoreMap: [],
				//添加商品已填的默认值
				default: {},
				//套票类别
				ticketPackageType: -1,
				//项目游玩
				checkPlayList: [],
				$ticketPackageTypeEnum: this.$ticketPackageTypeEnum,
				ticketPackageTypeShow: false,
				form: {},
				ticketPackageTypeList: [
					[{
							"id": this.$ticketPackageTypeEnum.UNDATED,
							'label': '不限时'
						},
						{
							"id": this.$ticketPackageTypeEnum.WEEK,
							'label': '周卡'
						},
						{
							"id": this.$ticketPackageTypeEnum.MONTH,
							'label': '月卡'
						},
						{
							"id": this.$ticketPackageTypeEnum.SEASON,
							'label': '季卡'
						},
						{
							"id": this.$ticketPackageTypeEnum.YEAR,
							'label': '年卡'
						},
						{
							"id": this.$ticketPackageTypeEnum.CUSTOMIZE,
							'label': '自定义'
						},
					]
				],
			}
		},
		onLoad(option) {
			let pages = getCurrentPages(); //获取所有页面栈实例列表
			let prevPage = pages[pages.length - 2]; //上一页页面实例

			if (prevPage.$vm.default) {
				this.default = prevPage.$vm.default
			}

			this.reverseDisplayStoreMap = new Map();

			if (prevPage.$vm.form.stores) {
				this.reverseDisplayStoreList = prevPage.$vm.form.stores;

				if (this.reverseDisplayStoreList && this.reverseDisplayStoreList.length > 0) {
					this.reverseDisplayStoreList.map(item => {
						this.reverseDisplayStoreMap.set(item.merchantStoreId, item)
					})
				}
			}

			if (prevPage.$vm.form.checkPlayList) {
				this.checkPlayList = prevPage.$vm.form.checkPlayList;
			}

			if (!uni.$u.test.isEmpty(option.ticketPackageType)) {
				this.ticketPackageType = option.ticketPackageType
			}
			//区分 是通用商品进入的页面还是套票进入
			if (!uni.$u.test.isEmpty(option.commodityType)) {
				this.commodityType = option.commodityType
			}
			this.findStore();
		},
		onReady() {
			this.getPomHeight();
			//明天
			let date = new Date()
			this.minDate = date.getTime() + 1000 * 60 * 60 * 24
		},
		methods: {
			limitTimesConfirm() {
				if (this.limitTimesCommodityStoreUpDown.booleanOfPlay != '0') {
					if (this.limitTimesItem.numberOfPlay == -1) {
						this.limitTimesItem.numberOfPlay = 0
					}
					let diff = this.limitTimesItem.numberOfPlay - this.limitTimes;
					let num = this.limitTimesCommodityStoreUpDown.totalTimes + diff;
					if (num < 0) {
						this.$helpers.toast('不能大过剩余次数次数');
						return;
					}
					this.limitTimesCommodityStoreUpDown.totalTimes = num
				}

				if (this.limitTimes == 0) {
					this.limitTimesItem.numberOfPlay = -1;
				} else {
					this.limitTimesItem.numberOfPlay = this.limitTimes;
				}
				this.limitTimesBoolean = false;
			},
			totalNumberOfPlayChange(item, num) {
				if (item.booleanOfPlay == '0') {
					item.totalTimes = -1;
				} else {
					item.totalTimes = num;
					let totalNumberOfPlay = 0;
					item.checkPlayList.forEach(data => {
						if (data.numberOfPlay != -1) {
							totalNumberOfPlay += data.numberOfPlay;
						}
					})

					if (totalNumberOfPlay < item.totalTimes) {
						item.totalTimes -= totalNumberOfPlay
					} else {
						item.checkPlayList.forEach(data => {
							data.numberOfPlay = -1
						})
					}
				}
			},
			showLimitTimesBoolean(item, data) {
				if (item.booleanOfPlay != '0') {
					if (this.$u.test.isEmpty(item.totalNumberOfPlay) || item.totalNumberOfPlay < 0) {
						this.$helpers.toast('请先设置总游玩次数');
						return;
					}
				}
				if (data.numberOfPlay != -1) {
					item.limitTimes = data.numberOfPlay
				} else {
					item.limitTimes = 0;
				}
				this.limitTimesBoolean = true;
				this.limitTimesCommodityStoreUpDown = item;
				this.limitTimesItem = data;
			},
			itemChangeBooleanOfPlay(item, event) {
				item.booleanOfPlay = event.detail.value
			},
			calculateExpirationDays(item) {
				if (item.amount != '' || item.amount > 0) {
					if (item.ticketPackageType == this.$ticketPackageTypeEnum.WEEK) {
						item.specifyDueTimeName = +item.amount * 7;
					} else if (item.ticketPackageType == this.$ticketPackageTypeEnum.MONTH) {
						item.specifyDueTimeName = +item.amount * 30;
					} else if (item.ticketPackageType == this.$ticketPackageTypeEnum.SEASON) {
						item.specifyDueTimeName = +item.amount * 90;
					} else if (item.ticketPackageType == this.$ticketPackageTypeEnum.YEAR) {
						item.specifyDueTimeName = +item.amount * 365;
					} else if (item.ticketPackageType == this.$ticketPackageTypeEnum.CUSTOMIZE) {
						item.specifyDueTimeName = +item.amount;
					}
				}

			},
			//确认选择套票类别
			ticketPackageTypeConfirm(e, item) {
				item.ticketPackageTypeName = e.value[0].label;
				item.ticketPackageType = e.value[0].id;
				if (item.ticketPackageType != this.$ticketPackageTypeEnum.UNDATED) {
					if (item.ticketPackageType == this.$ticketPackageTypeEnum.WEEK) {
						item.packageTypeName = '周';
					} else if (item.ticketPackageType == this.$ticketPackageTypeEnum.MONTH) {
						item.packageTypeName = '月';
					} else if (item.ticketPackageType == this.$ticketPackageTypeEnum.SEASON) {
						item.packageTypeName = '季';
					} else if (item.ticketPackageType == this.$ticketPackageTypeEnum.YEAR) {
						item.packageTypeName = '年';
					} else if (item.ticketPackageType == this.$ticketPackageTypeEnum.CUSTOMIZE) {
						item.packageTypeName = '天';
					}
					this.calculateExpirationDays(item);
				}

				this.ticketPackageTypeShow = false
			},
			ticketPackageTypeModelShow(item) {
				this.ticketPackageTypeShow = true
				this.form = item;
			},
			//设置游玩项目次数
			inputPlay(e, index, ind) {
				this.$nextTick(() => {
					this.storeList[index].checkPlayList[ind].numberOfPlay = e
				})
			},
			//确认购买后过期时间
			timeConfirm(e) {
				this.storeList[this.indexTime].specifyDueTime = uni.$u.timeFormat(e.value, 'yyyy-mm-dd')
				this.showTime = false
			},
			formatter(type, value) {
				if (type === 'year') {
					return `${value}年`
				}
				if (type === 'month') {
					return `${value}月`
				}
				if (type === 'day') {
					return `${value}日`
				}
				return value
			},
			switchReset(index) {
				this.storeList[index].resetExpirationDate = !this.storeList[index].resetExpirationDate;
			},
			switchOff(index) {
				this.storeList[index].quantityWrittenOff = !this.storeList[index].quantityWrittenOff;
			},
			//开启积分兑换开关
			switchPrice(index) {
				this.storeList[index].openExchange = !this.storeList[index].openExchange;
			},
			//开启回收
			switchRecovery(index) {
				this.storeList[index].openRecovery = !this.storeList[index].openRecovery;
			},
			//是否自提
			isSelfMentionChange(index) {
				this.storeList[index].isSelfMention = !this.storeList[index].isSelfMention
			},
			//是否直邮
			isDirectMailChange(index) {
				this.storeList[index].isDirectMail = !this.storeList[index].isDirectMail
			},
			//开启积分商城自助兑换
			goodsExchange(index) {
				this.storeList[index].integralMallSelfService = !this.storeList[index].integralMallSelfService
			},
			//收银系统
			pos(index) {
				this.storeList[index].posTerminal = !this.storeList[index].posTerminal
			},
			//小程序商城
			goods(index) {
				this.storeList[index].integralMallTerminal = !this.storeList[index].integralMallTerminal
				this.storeList[index].integralMallSelfService = !this.storeList[index].integralMallSelfService
			},
			keep() {
				if (this.selectedStores.length > 0) {
					for (let i = 0; i < this.selectedStores.length; i++) {


						if (uni.$u.test.isEmpty(this.selectedStores[i].retailPrice)) {
							this.$helpers.toast('请填写售价');
							return;
						}
						if (!this.selectedStores[i].isDirectMail && !this.selectedStores[i].isSelfMention && this
							.commodityType == 2) {
							this.$helpers.toast('寄邮最少选择一选');
							return;
						}
						if (!this.selectedStores[i].integralMallTerminal && !this.selectedStores[i].posTerminal) {
							this.$helpers.toast('上架终端最少选择一个');
							return;
						}
						if (this.commodityType == 3) {
							if (this.selectedStores[i].quantityWrittenOff && uni.$u.test.isEmpty(this.selectedStores[i]
									.everydayQuantityWrittenOff)) {
								this.$helpers.toast('请输入限制每天核销次数');
								return;
							}
						}
					}
				}


				this.selectedStores.forEach(item => {
					if (!item.openExchange) {
						item.integralConversionPrice = ''
						item.lotteryConversionPrice = ''
						item.coinConversionPrice = ''
					}
				})

				uni.showLoading({
					title: '预保存中...',
					mask: true
				})

				let pages = getCurrentPages(); //获取所有页面栈实例列表
				let prevPage = pages[pages.length - 2]; //上一页页面实例
				prevPage.$vm.commodityStoreUpDownStoreList = this.selectedStores //修改上一页data里面的data参数值


				setTimeout(() => {
					delta: 1,
					uni.navigateBack({
						complete: function(res) {
							uni.hideLoading();
						}
					});
				}, 1000)
			},
			//展开点击
			showOperate(index) {
				this.storeList[index].show = !this.storeList[index].show
				this.showIndex = this.showIndex == index ? -1 : index;
			},

			checkRetailPrice(e, index) {
				if (e == '.') {
					this.$helpers.toast('请输入以数字开头的售价');
					this.$nextTick(() => {
						this.storeList[index].retailPrice = null;
					});
					return
				}

				//正则表达试
				e = (e.match(/^\d*(\.?\d{0,2})/g)[0]) || null
				//重新赋值给input
				this.$nextTick(() => {
					this.storeList[index].retailPrice = e
				})
			},
			//整数 检验
			integerTest(e, name, index) {
				//正则表达试
				e = (e.match(/^(?!0\d)\d+$/.exec(e))) || null;
				//重新赋值给input
				this.$nextTick(() => {
					if (name === 1) {} else if (name === 2) {
						this.storeList[index].numberOfDays = e == null ? e : e[0]
					} else if (name === 3) {
						this.storeList[index].everydayQuantityWrittenOff = e == null ? e : e[0]
					} else if (name === 4) {
						this.storeList[index].integralConversionPrice = e == null ? e : e[0]
					} else if (name === 5) {
						this.storeList[index].lotteryConversionPrice = e == null ? e : e[0]
					} else if (name === 6) {
						this.storeList[index].coinConversionPrice = e == null ? e : e[0]
					} else {
						this.storeList[index].recoveryPrice = e == null ? e : e[0]
					}
				})
			},
			//选择过期时间
			selectTheTime(index) {
				this.indexTime = index;
				this.showTime = true;
			},
			//反显操作
			reverseDisplay() {
				this.storeList.forEach(item => {
					const commodityStoreUpDownStore = this.reverseDisplayStoreMap.get(item.merchantStoreId);
					if (!this.$u.test.isEmpty(commodityStoreUpDownStore)) {
						//已上架

						// 场地选中上架
						item.select = true;

						// 商品
						item.retailPrice = commodityStoreUpDownStore.retailPrice;

						// 兑换开关及价格
						item.openExchange = commodityStoreUpDownStore.openExchange;
						item.integralConversionPrice = commodityStoreUpDownStore.integralConversionPrice;
						item.lotteryConversionPrice = commodityStoreUpDownStore.lotteryConversionPrice;
						item.coinConversionPrice = commodityStoreUpDownStore.coinConversionPrice;

						// 回收开关及价格
						item.openRecovery = commodityStoreUpDownStore.openRecovery
						item.recoveryPrice = commodityStoreUpDownStore.recoveryPrice;

						if (commodityStoreUpDownStore.totalNumberOfPlay == -1) {
							item.totalNumberOfPlay = ''
							item.booleanOfPlay = '0'
						} else {
							item.totalNumberOfPlay = commodityStoreUpDownStore.totalNumberOfPlay
							item.booleanOfPlay = '1'
						}
						item.ticketPackageType = commodityStoreUpDownStore.ticketPackageType
						item.amount = commodityStoreUpDownStore.amount;
						item.ticketPackageTypeName = commodityStoreUpDownStore.ticketPackageTypeName;
						if (item.ticketPackageType != this.$ticketPackageTypeEnum.UNDATED) {
							if (item.ticketPackageType == this.$ticketPackageTypeEnum.WEEK) {
								item.packageTypeName = '周';
							} else if (item.ticketPackageType == this.$ticketPackageTypeEnum.MONTH) {
								item.packageTypeName = '月';
							} else if (item.ticketPackageType == this.$ticketPackageTypeEnum.SEASON) {
								item.packageTypeName = '季';
							} else if (item.ticketPackageType == this.$ticketPackageTypeEnum.YEAR) {
								item.packageTypeName = '年';
							} else if (item.ticketPackageType == this.$ticketPackageTypeEnum.CUSTOMIZE) {
								item.packageTypeName = '天';
							}
						}
						this.calculateExpirationDays(item);


						// 游玩项目
						item.checkPlayList = commodityStoreUpDownStore.checkPlayList;

						item.checkPlayList.forEach(data => {
							if (data.numberOfPlay == -1) {
								data.numberOfPlay = ''
								data.booleanOfPlay = '0'
							} else {
								data.booleanOfPlay = '1'
							}
						})

						item.resetExpirationDate = commodityStoreUpDownStore.resetExpirationDate;
						item.quantityWrittenOff = commodityStoreUpDownStore.quantityWrittenOff;
						item.everydayQuantityWrittenOff = commodityStoreUpDownStore.everydayQuantityWrittenOff;
						item.specifyDueTime = commodityStoreUpDownStore.specifyDueTime;
						item.numberOfDays = commodityStoreUpDownStore.numberOfDays;

						item.isDirectMail = commodityStoreUpDownStore.isDirectMail;
						item.isSelfMention = commodityStoreUpDownStore.isSelfMention;
						item.integralMallSelfService = commodityStoreUpDownStore.integralMallSelfService;
						item.integralMallTerminal = commodityStoreUpDownStore.integralMallTerminal;
						item.posTerminal = commodityStoreUpDownStore.posTerminal;

						item.ticketPackageTypeName = commodityStoreUpDownStore.ticketPackageTypeName;
						item.ticketPackageType = commodityStoreUpDownStore.ticketPackageType;
						item.amount = commodityStoreUpDownStore.amount;

						if (item.ticketPackageType != this.$ticketPackageTypeEnum.UNDATED) {
							if (item.ticketPackageType == this.$ticketPackageTypeEnum.WEEK) {
								item.packageTypeName = '周';
							} else if (item.ticketPackageType == this.$ticketPackageTypeEnum.MONTH) {
								item.packageTypeName = '月';
							} else if (item.ticketPackageType == this.$ticketPackageTypeEnum.SEASON) {
								item.packageTypeName = '季';
							} else if (item.ticketPackageType == this.$ticketPackageTypeEnum.YEAR) {
								item.packageTypeName = '年';
							} else if (item.ticketPackageType == this.$ticketPackageTypeEnum.CUSTOMIZE) {
								item.packageTypeName = '天';
							}
						}
						this.calculateExpirationDays(item);


						this.selectedStores.push(item);
					} else {
						//未上架

						// 商品
						item.retailPrice = this.default.retailPrice;

						// 兑换开关及价格
						item.openExchange = this.default.openExchange;
						item.integralConversionPrice = this.default.integralConversionPrice;
						item.lotteryConversionPrice = this.default.lotteryConversionPrice;
						item.coinConversionPrice = this.default.coinConversionPrice;

						// 回收开关及价格
						item.openRecovery = this.default.openRecovery
						item.recoveryPrice = this.default.recoveryPrice;


						item.totalNumberOfPlay = this.default.totalNumberOfPlay;
						item.resetExpirationDate = this.default.resetExpirationDate;
						item.quantityWrittenOff = this.default.quantityWrittenOff;
						item.everydayQuantityWrittenOff = this.default.everydayQuantityWrittenOff;
						item.specifyDueTime = this.default.specifyDueTime;
						item.numberOfDays = this.default.numberOfDays;
						item.isDirectMail = this.default.isDirectMail;
						item.isSelfMention = this.default.isSelfMention;
						item.integralMallSelfService = this.default.integralMallSelfService
						item.integralMallTerminal = this.default.integralMallTerminal;
						item.posTerminal = this.default.posTerminal;

						item.specifyDueTimeName = this.default.specifyDueTimeName;
						item.ticketPackageTypeName = this.default.ticketPackageTypeName;
						item.packageTypeName = this.default.packageTypeName;
						item.amount = this.default.amount;
						item.ticketPackageType = this.default.ticketPackageType;
						item.booleanOfPlay = this.default.booleanOfPlay

						item.limitTimes = this.default.limitTimes;
						item.totalTimes = this.default.totalTimes;

						// 游玩项目
						item.checkPlayList = this.checkPlayList;
					}
				});

				//编辑进来的时候判端是否全选
				this.allCheckStore();
			},
			//选择全部
			selectAllOperate(e) {
				this.selectAll = !this.selectAll;
				this.selectedStores = [];
				if (this.selectAll) {
					this.storeList.forEach((item, index) => {
						this.$set(item, 'select', this.selectAll)
						this.$set(item, 'show', this.selectAll)
						this.selectedStores.push(item)
					})
				} else {
					this.storeList.forEach((item, index) => {
						this.$set(item, 'select', this.selectAll)
						this.$set(item, 'show', this.selectAll)
					})
				}

			},
			//多选操作
			checkStore(e, index) {
				if (uni.$u.test.isEmpty(e)) {
					this.selectedStores = this.selectedStores.filter(item => item.merchantStoreId !== this.storeList[index]
						.merchantStoreId);
				} else {
					const index2 = this.selectedStores.findIndex(obj => obj.merchantStoreId === this.storeList[index]
						.merchantStoreId);
					if (index2 === -1) {
						this.selectedStores.push(this.storeList[index]); // 未找到对象，将其添加到数组末尾
					} else {
						this.selectedStores.splice(index2, 1, this.storeList[index]); // 找到对象，替换原始对象
					}
				}
				this.storeList[index].select = !uni.$u.test.isEmpty(e);
				//编辑进来的时候判端是否全选
				this.allCheckStore();
				this.storeList[index].show = !!this.storeList[index].select;
			},
			reachBottom() {},
			//判断是否全选
			allCheckStore() {
				if (this.selectedStores.length === this.storeList.length) {
					this.selectAll = true
				} else {
					this.selectAll = false
				}
			},
			findStore() {
				let param = {
					'commodityId': this.default.commodityId,
				}

				this.$api('merchantStore.findStoreShelves', param).then(res => {
					if (res.status == 0) {
						this.storeList = res.data;
						this.storeList.forEach((item, index) => {
							this.$set(item, 'select', this.selectAll)
						})
						this.reverseDisplay();
					} else {
						this.$helpers.toast('请求数据失败:' + res.msg);
					}
				})
			},
			getPomHeight() {
				let query = wx.createSelectorQuery().in(this)
				query.select('#topBox').boundingClientRect()
				query.exec(res => {
					let windowHeight = wx.getSystemInfoSync().windowHeight
					this.height = windowHeight
					for (let i = 0; i < res.length; i++) {
						this.height -= res[i].height;
					}
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.text-black {
		color: rgba(0, 0, 0, 0.8);
		font-size: 28rpx;
	}

	.text-ash {
		color: rgba(0, 0, 0, 0.8);
		font-size: 28rpx;
	}

	.placeholder {
		height: 170rpx;
	}

	.search-more-panel {
		width: 100vw;
	}

	.top-box {
		position: fixed;
		width: 100%;
		z-index: 22;
	}

	.flex {
		display: flex;
		justify-content: space-between;
		align-items: center;
	}

	.footer {
		position: fixed;
		bottom: 0;
		width: 100%;
		background-color: white;
		padding: 20rpx 0 40rpx;
	}

	.container-box {
		padding-top: 142rpx;

		.title {
			background-color: #fff;
			height: 120rpx;
			padding: 0 26rpx;

			.box-left {
				display: flex;
				align-items: center;
				width: 80%;

				.box-left-name {
					color: rgb(0, 0, 0);
					margin-left: 18rpx;
				}
			}

			.right-checkbox {
				width: 5%;
				display: flex;
				justify-content: flex-end;
				border: none;
				border-bottom: 1rpx solid rgba(0, 0, 0, 0.1);
			}
		}
	}

	.reset-container {
		padding: 36rpx 30rpx;
		border-top: 1rpx solid rgba(0, 0, 0, 0.1);
		background-color: #fff;

		.reset-box {
			margin: 63rpx 0 0 56rpx;
		}
	}

	.parameter-container {
		padding: 0 20rpx;
		background-color: #fff;

		.box {
			color: rgba(0, 0, 0, 0.8);
			padding: 36rpx 30rpx;
			border-top: 1rpx solid rgba(0, 0, 0, 0.1);
			display: flex;
			align-items: center;
		}

		.play {
			display: flex;
			justify-content: space-between;
			align-items: center;
			margin-bottom: 20rpx;
		}

		.share-flex-c {
			display: flex;
			align-items: center;
		}
	}

	.box {
		display: flex;
		align-items: baseline;
		justify-content: space-between;
		background-color: #fff;
		padding: 40rpx 30rpx;
	}

	.total-pay-box {
		display: flex;
		justify-content: flex-end;
		width: 100%;
		align-items: center;

		.total-pay-radio-group {
			width: 300rpx;

			.total-pay-radio-top {
				transform: scale(0.9);
				margin-bottom: 15rpx;
				width: 100%;
			}

			.total-pay-radio-bottom {
				transform: scale(0.9);
				width: 100%;

				.total-pay-radio-bottom-view {
					display: flex;
					align-items: center;
					width: 200rpx;
				}
			}
		}
	}

	.item-total-pay-box {
		width: 300rpx;
		display: flex;
		justify-content: space-around;
		width: 100%;


		.item-total-pay-radio-top {
			transform: scale(0.9);
			margin-bottom: 15rpx;
			width: 100%;
			text-align: center;
		}

		.item-total-pay-radio-bottom {
			transform: scale(0.9);
			width: 100%;
			text-align: center;

			.item-total-pay-radio-bottom-view {
				display: flex;
				align-items: baseline;
				width: 240rpx;
			}
		}
	}
</style>
